//地图定位
function setmap1(ss,call){
	var map;
	var watchId;
	var watchIdCount = 1;
	//alert("请求位置")
	if (navigator.geolocation) {
		//alert(JSON.stringify(navigator.geolocation))
	    watchId = navigator.geolocation.getCurrentPosition(showPosition, showError, {enableHighAcuracy: true, timeout: 5000, maximumAge:100000});
	    //设置定位缓存
	    //return watchId;
	} else {
		console.log("不支持定位模块")
	   // return false;
	}
	 
	 call();
}

function showPosition(position) {
	console.log("获取成功");
	console.log(position);
	sessionStorage.setItem("latitude",position.coords.latitude);//设置经度
	sessionStorage.setItem("longitude",position.coords.longitude);//设置纬度
//  positioning.latitude = position.coords.latitude;//纬
//  positioning.longitude = position.coords.longitude;//经
//  positioning.accuracy = position.coords.accuracy;//精确度
	
    return position
    
}
function showError(error) {
    var t_h = "错误信息：<br>";
    switch (error.code) {
        case error.TIMEOUT:
            t_h += "请求超时。如果在中国地区，谷歌 Chrome 或基于此内核的浏览器可能无法定位，您可以尝试其它浏览器如 IE / Edge。<br />A timeout occured! Please try again!";
            break;
        case error.POSITION_UNAVAILABLE:
            t_h += "抱谦，无法检测位置。如果设备有GPS，需在室外且GPS正常启动。<br />We can't detect your location. Sorry!";
            break;
        case error.PERMISSION_DENIED:
            t_h += "请充许浏览器访问地理位置请求。<br />Please allow geolocation access for this to work.";
            break;
        case error.UNKNOWN_ERROR:
            t_h += "发生未知错误<br />An unknown error occured!";
            break;
        default:
            t_h += "发生未知错误<br />An unknown error occured!";
            break;
    }
    console.log(t_h)
 
	return false;
    //失败
}
//计算两点间距离
function getGreatCircleDistance(lat1, lng1, lat2, lng2) {
    var EARTH_RADIUS = 6378137.0;//单位M
    var radLat1 = getRad(lat1);
    var radLat2 = getRad(lat2);
    var a = radLat1 - radLat2;
    var b = getRad(lng1) - getRad(lng2);
    var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
    s = s * EARTH_RADIUS;
    s = Math.round(s * 10000) / 10000.0;
    console.log(s)
    return s;
}
//
function getRad(d) {
    var PI = Math.PI;
    return d * PI / 180.0;
}
